<html>
<head>
    <style type="text/css">
        .fbButton,.fbButtonSuppressed:active,.fbButtonSuppressed:focus,.fbButtonSuppressed:hover{ background:#eee url(http://i.imgur.com/8dDyX.png) repeat 0 0;border:1px solid #999;border-bottom-color:#888;box-shadow:0 1px 0 rgba(0, 0, 0, .1);-webkit-box-shadow:0 1px 0 rgba(0, 0, 0, .1);cursor:pointer;display:-moz-inline-box;display:inline-block;font-size:11px;font-weight:bold;line-height:normal !important;padding:2px 6px;text-align:center;text-decoration:none;vertical-align:top;white-space:nowrap}
        .fbButton + .fbButton{ margin-left:4px }.fbButton:hover{ text-decoration:none }.fbButton:active,.fbButtonDepressed{ background:#ddd; border-bottom-color:#999; box-shadow:0 1px 0 rgba(0, 0, 0, .05); -webkit-box-shadow:0 1px 0 rgba(0, 0, 0, .05) }
        .fbButton .fbButtonText,.fbButton input{ background:none;border:0;color:#333;cursor:pointer;display:-moz-inline-box;display:inline-block;font-family:'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;font-size:11px;font-weight:bold;margin:0;outline:none;padding:1px 0 2px;white-space:nowrap}
        .fbButtonConfirm{background-color:#5b74a8;background-position:0 -48px;border-color:#29447e #29447e #1a356e}.fbButtonConfirm:active{background:#4f6aa3;border-bottom-color:#29447e}.fbButtonLarge,.fbButtonLarge .fbButtonText,.fbButtonLarge input{font-size:13px}.fbButtonText,.fbButtonConfirm input,.fbButtonConfirm.fbButtonDisabled .fbButtonText,.fbButtonConfirm.fbButtonDisabled input{color:#fff}
    </style>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript" src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
var invhead = '{{invhead}}';
var invmsg  = '{{invmsg}}';
var invreq  = {{invreq}};
var content = '{{content|safe}}';
var invsent = 0; // don't change needs to be zero for global variable on the invite count
function Send() { FB.ui({method: "apprequests", message: invmsg, title: invhead }, function (response) { if (response && response.to) {var invcount = response.to.length; invsent += invcount; if(invsent < invreq){ var invneed = invreq - invsent; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum(type, randomNum, invneed); }else{ top.location=content; } } else { if(invsent > 0){ var invneed = invreq - invsent; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum(type, randomNum, invneed); }else { var invneed = invreq; var randomNum = Math.ceil(Math.random()*100); var type = 'OK'; FBnum(type, randomNum, invneed); } } }) }        
function reload() { location.reload(true); }
function FBnum(type, randomNum, needmore) { var d = FB.Dialog.create({ closeIcon:false, onClose:function(){FB.Dialog.remove(this);}, visible:true, content:"<div id=\"dialog\" style=\"border:1px solid #555555;width:300px;\"><div id=\"newitemHead\" style=\"width:298px;height:25px;text-align:left;color:#FFFFFF;background-color:#6d84b4;font-size:14px;font-weight:bold;border:1px solid #3b5998;\"><div style=\"margin-left:10px;margin-top:5px;\">{{forcehead}}</div></div><div id=\"itemR\" style=\"font-size:12px;margin:0 auto;margin-top:15px;width:100%;text-align:center;background-color:#FFFFFF;\">{{forcebefore}}<font color='red'><b>"+needmore+"</b></font>{{forceafter}}<br /><br /><label class=\"fbButton fbButtonConfirm fbButtonLarge\"><input id=\""+randomNum+"\" value=\""+type+"\" onclick=\"FB.Dialog.remove(this);reload();\" type=\"submit\"></label><br /><br /></div></div>", width:'300' }); d.size = {width:d.clientWidth,height:d.clientHeight}; d.params = {method:null}; var oldOpen = window.open; window.open = function(){}; FB.UIServer.popup(d); window.open = oldOpen; return d; }
FB.init({appId  : '{{app_id}}', status : true, cookie : true, xfbml  : true , frictionlessRequests : true, oauth: true, channelUrl: "https://{{host_url}}/channel.html"}); FB.Canvas.setAutoResize();
$("#fb-root").html("<a href=\"javascript:void(0);\" onclick=\"Send();\">"+'{{first|safe}}'+"</a>");
</script>
</body>
</html>
